package com.kongy.filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author：ky
 * @date 2020-12-11 14:47
 */
public class CharacterEncodingFilter implements Filter {
    //初始化
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("CharacterEncodingFilter初始化");

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        System.out.println("CharacterEncodingFilter执行前。。");
        filterChain.doFilter(request, response);
        System.out.println("CharacterEncodingFilter执行后。。");


    }

    //销毁
    @Override
    public void destroy() {
        System.out.println("CharacterEncodingFilter销毁");


    }
}
